<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="../../plugins/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../css/normalize.css"/>
    <link rel="stylesheet" href="../../css/fa.css"/>
    <link rel="stylesheet" href="../../css/icon.css"/>
    <link rel="stylesheet" href="../../css/ares_animate.min.css"/>
    <link rel="stylesheet" href="../../css/ares_hover_variant.min.css"/>
    <link rel="stylesheet" href="../../css/ares_reboot.css"/>
    <link rel="stylesheet" href="../../css/app.min.css"/>
    <link rel="stylesheet" href="../../css/iframe.css"/>
    <style>

    </style>
</head>

<body class="ares-p">
<table class="layui-hide" id="table" lay-filter="table"></table>
<div id="pagination"></div>

<script type="text/html" id="tableBar">
    <button class="layui-btn layui-btn-xs" lay-event="check">查看</button>
</script>
<script type="text/javascript" src="../../plugins/layui/layui.js"></script>
<script type="text/javascript" src="../../aresExtends/config/layuiConfig.js"></script>
<script>
    layui.use(['table', 'utils', 'dateFilters', 'greyServices','qs'], function (table, utils, dateFilters, greyServices, qs) {
        var queryParams = qs.parse(location.search.substr(1));

        getList(queryParams.emrId, queryParams.isReferralHistory);

        function getList(emrId, isReferralHistory) {
            greyServices.grey_get_prescription_by_emr_id(emrId, 2, isReferralHistory).then(function (res) {
                var data = res.data,
                    list = data.prescription_list || [];
                table.render({
                    elem: '#table',
                    data: list,
                    limit: list.length + 1,
                    cellMinWidth: 80,
                    cols: [[
                        {title: '标题', templet: '<span>康复训练处方</span>'},
                        {title: '医生', templet: '<span>{{d.creator.name}}</span>'},
                        {
                            title: '状态',
                            templet: function (d) {
                                var status = d.status;
                                if (status == 0) {
                                    return '<b style="color: #FF5722;">进行中</b>';
                                }
                                else if (status == 1) {
                                    return '<b style="color: green;">完成</b>';
                                }
                                else if (status == -1) {
                                    return '<b style="color: red;">取消</b>';
                                }
                            }
                        },
                        {
                            title: '创建时间', width: 150,
                            templet: function (d) {
                                return dateFilters.dateTimeFormat(d.create_time);
                            }
                        },
                        {title: '操作', fixed: 'right', width: 60, templet: '#tableBar'}
                    ]]
                });
                table.on('tool(table)', function (obj) {
                    var data = obj.data;

                    switch (obj.event) {
                        case 'check':
                            openPrcpDetail(data);
                            break;
                    }
                    ;
                });
            });
        }

        function openPrcpDetail(data) {
            utils.layer.closeAll('iframe');
            var query = {
                selectPrcpId: data.id,
                isReferralHistory: 'emr_self'
            };
            utils.pushTopRoute('/training/detail/' + data.medical_record.id, query)
        }

    })
</script>


</body>

</html>
